package cn.edu.sdjzu.knoverse.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.edu.sdjzu.knoverse.model.dto.system.rolePower.AssignPowersToRoleDto;
import cn.edu.sdjzu.knoverse.model.vo.result.Result;
import  cn.edu.sdjzu.knoverse.service.RolePowerService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 角色和权限
 */
@Tag(name = "角色和权限", description = "角色和权限相关接口")
@RestController
@RequestMapping("/rolePower")
public class RolePowerController {

    @Autowired
    private RolePowerService rolePowerService;

    @SaCheckLogin
    @Operation(summary = "根据角色id获取权限内容", description = "根据角色id获取权限内容")
    @GetMapping("noManage/getPowerListByRoleId")
    public Result<List<String>> getPowerListByRoleId(Long id) {
        List<String> voList = rolePowerService.getPowerListByRoleId(id);
        return Result.success(voList);
    }

    @SaCheckPermission("rolePower::assignPowersToRole")
    @Operation(summary = "为角色分配权限", description = "为角色分配权限")
    @PostMapping("assignPowersToRole")
    public Result<String> assignPowersToRole(@Valid @RequestBody AssignPowersToRoleDto dto) {
        rolePowerService.assignPowersToRole(dto);
        return Result.success();
    }
}
